/*******************************发送分页查询ajax请求******************************/
var currentPage = 1; //当前页
var pageSize = 5; //每页显示条数
var totalCount = 0; //总记录条数
var totalPage = 0; //总页数

function PageFind() {
    //1.获取输入框上的值
    var fileName = $('#fileName').val();
    var startTime = $('#startTime').val();
    var endTime = $('#endTime').val();
    var userId = sessionStorage.getItem("userId");
    //2.发送ajax
    $.ajax({
        url: "fileInfo/pageFind",
        type: "post",
        dataType: "JSON",
        data: {
            FileName: fileName,
            startTime: startTime,
            endTime: endTime,
            userId:userId,
            currentPage: currentPage,
            pageSize: pageSize
        },
        success: function(pageBean) {
            //设置参数
            totalCount = pageBean.totalCount;
            totalPage = parseInt(pageBean.totalPage);
            //数据插入函数
            showTableData(pageBean.list);
        }
    });
};
//发送ajax
PageFind();

function showTableData(dataList) {
    //1.设置当前页和总页数
    var pageNumberData = currentPage + '/' + totalPage;
    $('#pageNumber').html(pageNumberData);
    //2.设置表格数据
    //2.1清空表格
    $('#tableData').html('');
    //2.2遍历数据
    var trs = '';
    for (var i = 0; i < dataList.length; i++) {
        var dataDetail = dataList[i];
        //改日期
        var cDate = new Date(dataDetail.upCtime).format('yyyy-MM-dd hh:mm:ss');
        var splitStrs = dataDetail.savePath.split("\\");
        var downLoadFileName = splitStrs[splitStrs.length-1];
        var hrefStr = "fileInfo/download?filename="+downLoadFileName+"&path="+dataDetail.savePath;
        var tr = `
                <tr>
                    <td>${dataDetail.fileName}</td>
                    <td>${dataDetail.fileSize}</td>
                    <td>${cDate}</td>
                    <td>${dataDetail.fileState}</td>
                    <td>${dataDetail.typeName}</td>
                    <td>${dataDetail.fileScore}</td>
                    <td>${downLoadFileName}</td>
                    <td>
                        <!--<button class="btn btn-mini " type="button" id="downLoadFile">下载文件</button>-->
                        <a href=${hrefStr}>下载文件</a>
                    </td>
                </tr>
                `;
        //添加数据
        trs += tr;
    }
    //2.3将数据加入
    $('#tableData').html(trs);
};
//上一页 下一页按钮 搜索 重置 触发事件
$('#prePageBtn').click(function() {
    currentPage -= 1;
    if (currentPage < 1) {
        currentPage = 1;
        return;
    }
    PageFind();
});
$('#nextPageBtn').click(function() {
    currentPage += 1;
    if (currentPage > totalPage) {
        currentPage = totalPage;
        return;
    }
    PageFind();
});
$('#searchBtn').click(function() {
    PageFind();
});
$('#reSetBtn').click(function() {
    $('#fileName').val('');
    $('#startTime').val('');
    $('#endTime').val('');
});